A good answer might be:

  1. How many frames are there?
    • Just one.
  2. What GUI components will it contain?
    • The "Red" button and the "Green" button.
  3. What objects generate events?
    • Both buttons and the frame.
  4. What objects receive events?
    • A listener for window events, and
    • a listener for button events.

The Frame

You might have said that each button needs its own listener. That would work, we can use just one listener. First write a class definition for the container frame. Here is a skeleton:

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*; 

public class TwoButtons extends  ________ implements  _________
{


  . . . . more code will go here . . . . 

  public static void main ( String[] args )
  {
    TwoButtons demo  = new __________ ;
    

    . . . . more code will go here . . . . 
    
    demo.setSize( 200, 150 );     
    demo.setVisible( true );      

  }
}

. . . . more code will go here . . . . 

For now, just decide what class this new one extends and what interface it will implement. Then fill in the constructor in main()

QUESTION 4:

Fill in the blanks.